//
//  MineVC.m
//  ConvenientlyTake
//
//  Created by 张奇 on 2022/12/20.
//

#import "MineVC.h"
#import "LoginVC.h"
#import "TGPreviewFileView.h"
#import "AppDelegate+JPush.h"
#import "MapTestViewController.h"

@interface MineVC ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *telLabel;


@property (weak, nonatomic) IBOutlet UIView *bgView;


@end

@implementation MineVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshData) name:KNotificationWithLogInRefreshData object:nil];
}

- (void)setupNavigationItems {
    [super setupNavigationItems];
    [self setNavStyleWhite];
}

- (void)setupUI {
    self.fd_prefersNavigationBarHidden = YES;
    self.navigationController.navigationBarHidden = YES;
    
    self.bgView.layer.qmui_maskedCorners = QMUILayerMinXMinYCorner|QMUILayerMaxXMinYCorner;
    self.bgView.layer.cornerRadius = 25;
    
    self.nameLabel.text = [TGUserModel getUserEntity].name;
    self.telLabel.text = R([TGUserModel getUserEntity].phoneNumber);
}

- (void)refreshData {
    self.nameLabel.text = R([TGUserModel getUserEntity].name);
    self.telLabel.text = R([TGUserModel getUserEntity].phoneNumber);
}

- (IBAction)clickPrivateProtocal:(UIButton *)sender {
//    TGPreviewFileView *previeView = [[TGPreviewFileView alloc] initWithTitle:@"《随手拍用户服务协议》" height:SCREEN_HEIGHT];
//    previeView.linkStr = AgreementURL;
//    [previeView show];
    
    MapTestViewController *vc = [[MapTestViewController alloc] init];
    [self pushViewController:vc complent:nil];
}


- (IBAction)clickLogOut:(UIButton *)sender {
    [TGLEEAlert alertTitle:@"是否确认退出登录" message:nil cancelTitle:@"取消" sureTitle:@"确认" click:^(NSInteger index) {
        if (index==1) {
            [self logOut];
        }
    }];
}

#pragma mark -
-(void)logOut {
    
    [TGProgressHUD showHUD:nil];

//    [TGMineMangeAPIRequest logOutWithSuccess:^(TGResponseItem *responseItem) {
//        [TGProgressHUD dismissMPHUD];
//        if (responseItem.success) {
    
    //清除别名
    [AppDelegate deleteAlias];
    //重置app角标
    [AppDelegate setJPshBadgeWithBadge:0];
    
    [TGGCD executeAfterTime:1 task:^{
        [TGUserModel remove];
        [TGProgressHUD dismissMPHUD];
        
        LoginVC *loginVC = [[LoginVC alloc] init];
        loginVC.complentBlock = ^{
            TGTabBarVC *tabarController = [[TGTabBarVC alloc] init];
            [[UIApplication sharedApplication].keyWindow setRootViewController:tabarController];
        };
        [[UIApplication sharedApplication].keyWindow setRootViewController:loginVC];
    }];
    
//            [TGGCD executeMainAsyncTask:^{
//                //清除别名
//                [AppDelegate deleteAlias];
//            }];
            //重置app角标
//            [AppDelegate setJPshBadgeWithBadge:0];
            
//        } else {
//            [TGProgressHUD showMBHUDErrorTip:responseItem.message];
//        }
//
//    } fail:^(NSError *error) {
//        [TGProgressHUD showHUDTipNetError];
//
//    }];
    

}

@end
